/*
 * Copyright 2006-2008 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.martinimix.view.common.html;

import com.bluemartini.htmlapp.Content;

/**
 * Provides methods to create an HTML IMG tag.
 * 
 * @author Scott Rossillo
 *
 */
public class Image extends HTMLTag {
	
	public Image(Content content) {
		
		super("img");
		
		put("src", content.getPath());
		
		int border = content.getInteger("ATR_ImageBorder", -1);
		int width = content.getInteger("ATR_ImageWidth", -1);
		int height = content.getInteger("ATR_ImageHeight", -1);
		
		int vspace = content.getInteger("ATR_ImageVspace", -1);
		int hspace = content.getInteger("ATR_ImageHspace", -1);
		
		String alt = content.getString("ATR_AltText");
		String style = content.getString("ATR_Style");
		
		if(border >= 0) { this.setBorder(border); }
		if(width >= 0) { this.setWidth(width); }
		if(height >= 0) { this.setHeight(height); }
		
		if(vspace >= 0) { this.put("vspace", String.valueOf(vspace)); }
		if(hspace >= 0) { this.put("hspace", String.valueOf(hspace)); }
		
		
		if(alt != null) { this.put("alt", alt); }
		if(style != null) { this.put("style", style); }
	}
	
	public Image(String source) {
		super("img");
		put("src", source);
	}
	
	public boolean setBorder(int border) {
		
		return put("border", String.valueOf(border));
	}
	
	public boolean setHeight(int height) {
		
		return put("height", String.valueOf(height));
	}

	public boolean setWidth(int width) {
		
		return put("width", String.valueOf(width));
	}
}
